<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head>
    <title>品规数</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>

    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>品规数</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active">药品招标管理</li>
            <li class="active">采购项目管理</li>
            <li class="active">招标目录管理</li>
        </ol>
    </section>
     <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class=" form-inline">
                <div class="form-group form-group-xs">
                     <label>目录名称：</label>
                        <input class="form-control" type="text" id="drugcatalogName" placeholder="目录名称" />
                    </div>
                    <div class="form-group form-group-xs">
                     <label>品规编码：</label>
                        <input class="form-control" type="text" id="qualityspecCode" placeholder="药品编码" />
                    </div>
                     <div class="form-group form-group-xs">
                        <label>通用名：</label>
                        <input class="form-control" type="text" id="qualityspecName" placeholder="通用名" />
                    </div>
                    <!-- <div class="form-group form-group-xs">
                        <label>药品分类：</label>
                        <input class="form-control" type="text" id="classify" placeholder="药品分类" />
                    </div> -->
                    
                    
                    <button type="button" class="btn btn-success btn-sm" onclick="search()">查&nbsp;询</button>
                </div>
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <div class=" box box-warning bottongroup">
        	 <label class="btn btn-default btn-sm" onclick="batchChangeStatus(1)">启&nbsp;用</label>
             <label  class="btn btn-default btn-sm" onclick="batchChangeStatus(0)">停&nbsp;用</label>
             <a href="toBidProjectCheckList.html" class="btn btn-default btn-sm back" >返&nbsp;回</a>
        </div>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
    
    
    //查询
    function search() {
    	var drugcatalogName = $("#drugcatalogName").val();
        var qualityspecCode = $("#qualityspecCode").val();
        var qualityspecName = $("#qualityspecName").val();
        $("#gridlist").jqGrid("clearGridData");
            $("#gridlist").jqGrid('setGridParam',{ 
            url:"${ctx}/bidProject/getHaveAddDrugDataList.html",
            mtype: "POST",
            datatype:'json',
            postData:{"drugcatalogName":drugcatalogName,
            		"qualityspecCode":qualityspecCode, 
            		"qualityspecName":qualityspecName,
            		"projId":"${projId}"},
            page :  1
        }).trigger("reloadGrid"); //重新载入  
    }
        $(function () {
            
            $("#gridlist").jqGrid({
                url: "${ctx}/bidProject/getHaveAddDrugDataList.html",
                mtype: "POST",
                postData: { "projId" : "${projId}"},
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: ['bidProjqualityspecId', '目录编号', '目录名称','品规编码', '通用名','剂型','规格','品规属性','品规分类','品规序号'],
                colModel: [
                    { name: 'bidProjqualityspecId',hidden:true, width: 10, align:"center", sortable: false},
                    { name: 'drugcatalogCode', width: 80 , align:"center" ,sortable: false},
					{ name: 'drugcatalogName', width: 120 , align:"center" ,sortable: false},
                    { name: 'qualityspecCode', width: 80 , align:"center",sortable: false},
                    { name: 'qualityspecName', width: 100 , align:"center" ,sortable: false},
					{ name: 'formName', width: 100 , align:"center" ,sortable: false},
					{ name: 'specName', width: 100 , align:"center" ,sortable: false},
					{ name: 'attribute', width: 80 , align:"center" ,sortable: false,
						formatter :function(val){
							return val==0?"国家":(val==1?"省增补":"");
						}
					},
					{ name: 'qualityspecClass', width: 100 , align:"center" ,sortable: false},
                    { name: 'qualityspecIndex', width: 80 , align:"center" ,sortable: false}
                ],
                
                rowNum: 20,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                caption: "${name}  -已添加品规数 ",
                //序号宽度自动变化
                gridComplete:function(){        
                    var page = $("#gridlist").jqGrid('getGridParam','page');
                    var rows = $('#gridlist').getGridParam("rowNum");
                    var maxnum = (rows*page).toString();
                    var len = (maxnum.length)*10;
                    $('.jqgfirstrow').find('td').eq(0).css('width',len+'px');
                    $('#gridlist_rn').css('width',len+'px');
                },
                jsonReader: {
                    repeatitems: false,
                    id: "drugId"
                },    
                loadComplete: function (data) { //完成服务器请求后，回调函数
                	var projId = data.form;
                	if(projId!=null && projId!=""){
                		$(".back").remove();
                  }
                }
                
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });


        //启用禁用
         function changeStatus(id, status) {
            $.ajax({
            	 type:"POST",
                 url:"${ctx}/bidProject/changeStatus.html",
                 data:{"projDrugId":id,"status":status},
                 dataType:"json",
                 success: function(result) {
                     if (result) {
                         $.HN.message.alert("保存成功！", "消息", "success");
                     	$("#gridlist").jqGrid('setGridParam',{  
                	        datatype:'json'
                	    }).trigger("reloadGrid");
                     } else {
                         $.HN.message.alert("保存失败！", "消息", "error");
                     }
                 }
            });
        } 
        //批量启用、停用
         function batchChangeStatus(status) {
        	 var msg = "";
 			if (status == "0") {
 				msg = "停用";
 			} else if (status == "1") {
 				msg = "启用";
 			}
             var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
             if (rowIds.length <= 0) {
                 $.HN.message.alert("请选择要操作的行！", "消息", "error");
                 return;
             }
             $.HN.message.confirm('确定'+msg+'吗？', '', '').on(function (e) {
        		 if(e){
             var list = [];
             for (var i=0; i<rowIds.length; i++) {
            	 var rowdata = $("#gridlist").jqGrid(
							'getRowData', rowIds[i]);
                 list.push({ "bidProjqualityspecId":rowdata.bidProjqualityspecId,"status":status});
             }
             $.post("${ctx}/bidProject/batchSwitchDrugStatus.html", {
                 "array" : json.jsonToString(list),"status":status
             }, function(result) {
                 if (result) {
                     $.HN.message.alert("操作成功！", "消息", "success");
                     $("#gridlist").jqGrid('setGridParam',{  
             	        datatype:'json'
             	    }).trigger("reloadGrid");
                 } else {
                     $.HN.message.alert("操作失败！", "消息", "error");
                 }
             }, "json")
		      }
				 
			 });
         }

         
    </script>
</body>
</html>